<?php if($action =='update'):?>
<form method="post" action="<?php echo App::Config()->baseUrl("/managestore/shippingrole/update/{$id}");?>">
	<div class="box box-left">
		<div class="title">
			<h5><?php echo $this->__('Shipping Countries');?></h5>
		</div>
			<div class="form">	
			<?php	
				$savedData = unserialize($Roles['description']);
				$Grid = App::Module('DataGrid')->clear();
				$Grid->setHeader(array( 'Name','Price'));
				foreach(App::Component("AppStore")->Helper("Data")->CountryList('Active') as $Country){
					$Grid->addRow(
						$Country['name'],
						App::Html()->inputTag("data[Countries][{$Country['code']}]",
							(isset($savedData['Countries'][$Country['code']]) ? $savedData['Countries'][$Country['code']] : ''),
							array("style"=>"width:50px","class"=>"rate_box app_input")
						)
					);
				}
				$Grid->setFooter('');
				$Grid->Render();
			?>
			</div>
	</div>
	
	<div class="box box-right">
		<div class="title">
			<h5><?php echo $this->__('Shipping Role Information');?></h5>
		</div>
		<div class="form">
			<h3 class="first">
				<input type="button" onclick="javascript:history.go(-1)" value="<< Back" />
				<input type="reset" value="Reset" />
				<input type="button" value="Clear"  onclick="jQuery('.rate_box').val('')" />
				<input type="button" value="Set All Zero(Free)"  onclick="jQuery('.rate_box').val('0')" />
				<input type="submit" value="Save" />
			</h3>			
			<?php	
				$Grid = App::Module('DataGrid')->clear()
					->setDisplay('FormListing')
					->addRow('Role Name',$Roles['title'])
					->addRow('Create Date',App::Helper('Date')->dateformated($Roles['entrydate'],'long'))
					->addRow('Default Rate',App::Html()->inputTag('data[Shipping][defaultrate]',isset($savedData['Shipping']['defaultrate']) ? $savedData['Shipping']['defaultrate'] : '0',array('class'=>'default_rate app_input')))
					->addRow('Cal. Method',App::Html()->selectTag('data[Shipping][calmethod]',array("same4allqty"=>"Same for All Qty","multiplybyqty"=>"Multiply By Qty","setbyscript"=>"Set By Script"),(isset($savedData['Shipping']['calmethod']) ? $savedData['Shipping']['calmethod'] : 'same4allqty'),null,array('off_blank'=>"Yes")))
					->addRow("PHP Script",App::Html()->textareaTag('data[Shipping][script]',
(isset($savedData['Shipping']['script']) ? $savedData['Shipping']['script'] : 
'switch($Shipping->getCountry()){
    case "US":
      if($Shipping->getQty() < 5 ) return 10;
      else return $Shipping->getQty() * 2;
      break;
    case "CA": 
      if($Shipping->getQty() < 5 ) return 12;
      else return $Shipping->getQty() * 3;
      break;	  
    default: 	
      return $Shipping->getQty() * 5;   
}'),array("class"=>"app_input","rows"=>"15")))
					->Render();
				
			?>			
			</div>
	</div>
	<div class="box box-right">
		<div class="title">
			<h5><?php echo $this->__('Guide Line');?></h5>
		</div>
		<div class="form">
			<ol class="list">
				<li>1) Default rate use if country wise rate is not set.</li>
				<li>2) Set 0(Zero) to assing free shipping</li>
				<li>3) Select Cal. method to manage rate with quantity</li>
			</ol>
		</div>
	</div>	
</form>
<?php else:?>
	<div class="box box-left">
		<div class="title">
			<h5><?php echo $this->__('Shipping Countries');?></h5>
		</div>
			<div class="form">
			<?php	
				$Grid = App::Module('DataGrid');
				$Grid->setHeader(array( 'Name','Code','Status'));
				foreach(App::Component("AppStore")->Helper("Data")->CountryList() as $Country){
					$Grid->addRow(
						$Country['name'],
						$Country['code'],
						 App::Html()->getTag("span",array("style"=> "color:" . (($Country['shippingstatus'] == 'Active') ? "green" : "red")),$Country['shippingstatus'])
					
						. ' (' . App::Html()->LinkTag(
							App::Config()->baseUrl("/information/manage/countries/update/{$Country['id']}"),
							$this->__('Chnage')
						) . ')'
						
					);
				}
				$Grid->setFooter('');
				$Grid->Render();
			?>
			</div>
	</div>
	<div class="box box-right">
		<div class="title">
			<h5><?php echo $this->__('Shipping Role');?></h5>
		</div>
			<div class="form">
			<?php
				$Grid = App::Module('DataGrid')->Clear();
				$Grid->setHeader(array('Title','Status', 'Action'));
				foreach($Roles['data'] as $Role){
					$Grid->addRow(
						$Role['title'],
						"Complete",
						App::Html()->linkTag(
							App::Config()->baseUrl("/managestore/shippingrole/update/{$Role['id']}"),"Set Role")
					);
				}
				$Grid->setFooter('');
				$Grid->Render();
			?>
			</div>
	</div>
<?php endif;?>